package com.dc.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("");
        resp.getWriter().append("登录成功");
        String account=req.getParameter("account");
        System.out.println(account);
       String password=req.getParameter("password");
        System.out.println(password);
        HttpSession session=(HttpSession) req.getSession();
        if(account.equals("阿娇")&&password.equals("qqq")){
session.setAttribute("username",account);
resp.sendRedirect("/main/index.jsp");
        }else{
            String attr="<script> alert('发生错误')</script>";
            resp.getWriter().append(attr);
            resp.sendRedirect("Login.jsp");
        }
    }

}
